package org.jheuristics.ga.scalers;

import org.jheuristics.ga.transformations.FitnessToDoubleTransformation;

/**
 * TODO
 *
 * @author Marcell Manfrin, marcell@ourgrid.org, Jan 9, 2006
 */
public abstract class AbstractFitnessScaler implements FitnessScaler {
    private FitnessToDoubleTransformation tranformation;

    /**
     * TODO
     * 
     * @param transformation
     */
    protected AbstractFitnessScaler(FitnessToDoubleTransformation transformation) {
        setTranformation(transformation);
    }

    /**
     * TODO
     *
     * @return Returns the tranformation.
     */
    public FitnessToDoubleTransformation getTranformation() {
        return tranformation;
    }
 
    /**
     * TODO
     *
     * @param tranformation The tranformation to set.
     */
    public void setTranformation(FitnessToDoubleTransformation tranformation) {
        if (null == tranformation) {
            // TODO: ERROR MSG
            throw new NullPointerException();
        }
        this.tranformation = tranformation;
    }

    /**
     * TODO
     *
     * @param fitness
     * @return
     * @see org.jheuristics.ga.scalers.FitnessScaler#scale(java.lang.Comparable[])
     */
    public double[] scale(Comparable[] fitness) {
        if (null == fitness) {
            // TODO: ERROR MSG
            throw new NullPointerException();
        }
        for (int i = 0; i < fitness.length; i++) {
            if (null == fitness[i]) {
                // TODO: ERROR MSG
                throw new NullPointerException();
            }
        }

		double[] values = new double[fitness.length];
        for (int i = 0; i < fitness.length; i++) {
	        values[i] = tranformation.toDouble(fitness[i]);
        }
		return scale(values);
    }

	/**
	 * TODO
	 *
	 * @param fitness
	 * @return
	 */
	protected abstract double[] scale(double[] fitness);
    
}
